package logiexport.paneles;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import logiexport.bd.App;
import logiexport.pojos.Presupuesto;
import logiexport.pojos.User;
import logiexport.session.SignInSession;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.PropertyModel;




public class PanelPresu extends Panel implements Serializable {
	
	SignInSession s = SignInSession.get();
	User user = s.getUser();
	App app =  new App();
	
	List<Presupuesto> listapresu;
	

	public PanelPresu(String id) {
		super(id);
		
		// TODO Auto-generated constructor stub

		@SuppressWarnings("unchecked")
		ListView listview = new ListView("presulist", new PropertyModel<List<Presupuesto>>(this, "listapresu") ) {

			private static final long serialVersionUID = 1L;

			@SuppressWarnings("rawtypes")
			@Override
			protected void populateItem(ListItem item) {

			
				final Presupuesto p = (Presupuesto) item.getModelObject();	
				
			
					
					item.add(new Label("id_p",p.getId_p()));
					
					
					  final Link pdfLink = new Link("apdf")
				        {
				            @Override
				            public void onClick()
				            {
				                
				            }
				        };
				        
				       
				        pdfLink.add(new AttributeModifier("href", "http://localhost/pdf/"+p.getId_p()+".pdf"));
				        
				        item.add(pdfLink);
					
					
					
					
					AjaxLink<String> visible = new AjaxLink<String>("visible") {
						
						@Override
						public void onClick(AjaxRequestTarget target) {
							// TODO Auto-generated method stub
							
							app.hidden(p);
							target.add(PanelPresu.this);
							
							
						}
					};
					
					item.add(visible);
					
		
			}
		};

		add(listview);
			

	}

	
	public void load() {
		
		listapresu =  new LinkedList<Presupuesto>();
		
		listapresu.clear();
		
		listapresu =  app.lista_presu(user);
		
		
	}
	

	@Override
	protected void onConfigure() {
		// TODO Auto-generated method stub
		super.onConfigure();
		
		System.out.println("Dentro del onConfigure");
		
		listapresu =  new LinkedList<Presupuesto>();
		
		listapresu.clear();
		
		listapresu =  app.lista_presu(user);
		
		/*for(int i=0; i< listapresu.size(); i++) {
			
			System.out.println("Presu: "+listapresu.get(i).getId_p());
			
		}*/
		
		
		
		
	}
	

	
	
	
	
	

}
